#include "ReportAssert.hpp"
#include "ReportAssertImpl.hpp"
#include "AssertException.hpp"
#include "CurrentTest.hpp"
#include "TestResults.hpp"
#include "TestDetails.hpp"

namespace UnitTest {
    namespace
    {
        bool& AssertExpectedFlag()
        {
            static bool s_assertExpected = false;
            return s_assertExpected;
        }
    }

    void ReportAssert(char const* description, char const* filename, int lineNumber)
    {
        Detail::ReportAssertEx(CurrentTest::Results(), CurrentTest::Details(),
                                description, filename, lineNumber);
    }

    namespace Detail {
        void ReportAssertEx(TestResults* testResults,
                                           const TestDetails* testDetails,
                                           char const* description,
                                           char const* filename,
                                           int lineNumber)
        {
            if (AssertExpectedFlag() == false)
            {
                TestDetails assertDetails(testDetails->testName, testDetails->suiteName, filename, lineNumber);
                testResults->OnTestFailure(assertDetails, description);
            }

            ExpectAssert(false);

            throw AssertException();

        }

         void ExpectAssert(bool expected)
        {
            AssertExpectedFlag() = expected;
        }

        bool AssertExpected()
        {
            return AssertExpectedFlag();
        }
    }
}